/*
 * Copyright (c) 2022 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef OHOS_FORM_FWK_FORM_RENDER_IMPL_H
#define OHOS_FORM_FWK_FORM_RENDER_IMPL_H

#include "form_render_stub.h"

#include <memory>
#include <singleton.h>
#include "runtime.h"
#include "js_runtime.h"
#include "context_impl.h"
#include "want.h"
#include "ui_content.h"

namespace OHOS {
namespace AppExecFwk {
namespace FormRender {
using OHOS::AAFwk::Want;
class FormRenderImpl : public FormRenderStub,
                       public std::enable_shared_from_this<FormRenderImpl> {
    DECLARE_DELAYED_SINGLETON(FormRenderImpl)
public:
    /**
     * @brief add form renderer. This is sync API.
     * @param formJsInfo The form js info.
     * @param want Indicates the {@link Want} structure containing form info.
     * @param callerToken Caller ability token.
     * @return Returns ERR_OK on success, others on failure.
     */
    virtual int32_t AddFormRenderer(const FormJsInfo &formJsInfo, const Want &want,
        const sptr<IRemoteObject> &callerToken) override { return 0; }

    /**
     * @brief Render form. This is sync API.
     * @param formJsInfo The form js info.
     * @param want Indicates the {@link Want} structure containing form info.
     * @param callerToken Caller ability token.
     * @return Returns ERR_OK on success, others on failure.
     */
    int32_t RenderForm(const FormJsInfo &formJsInfo, const Want &want,
        const sptr<IRemoteObject> &callerToken) override;
    void SetRuntime(AbilityRuntime::Runtime& runtime);
private:
    /**
     * @brief Init form. This is sync API
     *
     * @param formJsInfo The form js info
     * @return Returns ERR_OK on success, others on failure.
     */
    int32_t InitForm(const FormJsInfo &formJsInfo, const Want &want);

private:
    static sptr<FormRenderImpl> instance_;
    std::shared_ptr<AbilityRuntime::ContextImpl> context;
    AbilityRuntime::Runtime *runtime_;
    std::shared_ptr<Ace::UIContent> uiContent_;
};
}  // namespace FormRender
}  // namespace AppExecFwk
}  // namespace OHOS
#endif  // OHOS_FORM_FWK_FORM_RENDER_IMPL_H
